﻿using Compass.Wasm.Server.Services.Wms;
using Compass.Wasm.Shared;
using Compass.WmsService.Infrastructure;
using System.ComponentModel.DataAnnotations;
using Compass.Wasm.Shared.Wms;

namespace Compass.Wasm.Server.Controllers.Wms
{
    [Route("api/[controller]")]
    [ApiController]
    [UnitOfWork(typeof(WmsDbContext))]
    public class VendorController : ControllerBase
    {
        #region ctor
        private readonly IVendorService _service;
        public VendorController(IVendorService service)
        {
            _service = service;
        }
        #endregion

        #region 基本增删改查
        [HttpGet("All")]
        public async Task<ApiResponse<IEnumerable<VendorDto>>> GetAll() => await _service.GetAllAsync();

        [HttpGet("{id}")]
        public async Task<ApiResponse<VendorDto>> GetSingle([RequiredGuid] Guid id) => await _service.GetSingleAsync(id);

        [HttpPost("Add")]
        public async Task<ApiResponse<VendorDto>> Add(VendorDto dto) => await _service.AddAsync(dto);

        [HttpPut("{id}")]
        public async Task<ApiResponse<VendorDto>> Update([RequiredGuid] Guid id, VendorDto dto) => await _service.UpdateAsync(id, dto);

        [HttpDelete("{id}")]
        public async Task<ApiResponse<VendorDto>> Delete([RequiredGuid] Guid id) => await _service.DeleteAsync(id);

        #endregion

        #region 扩展查询
        [HttpGet("Number")]
        public async Task<ApiResponse<VendorDto>> GetSingleByNumber(string number) => await _service.GetSingleByNumberAsync(number);
        //http://10.9.18.31/api/Vendor/Number?number=500002

        [HttpGet("Top5")]
        public async Task<ApiResponse<IEnumerable<VendorDto>>> GetGetTop5ByKeyword(string? keyword) => await _service.GetTop5ByKeywordAsync(keyword);
        //http://10.9.18.31/api/Vendor/Top5?keyword=xxxx
        #endregion

    }
}
